/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.car;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.car.CarApply;
import com.unis.service.car.CarApplyService;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2013-01-11
 */
@Controller
@RequestMapping("/carapply")
public class CarApplyController {

    private CarApplyService carapplyService;

    /****************************************
     * Insert a instace of CarApply
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertCarApply(@RequestBody CarApply carapply) throws Exception {
        carapply.setStatmentId("CarApply.insert");
        String status = "failure";
        carapplyService.insert(carapply);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of CarApply
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody CarApply carapply) throws Exception {
        carapply.setStatmentId("CarApply.update");
        String status = "failure";
        carapplyService.update(carapply);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of CarApply
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody CarApply carapply) throws Exception {
        carapply.setStatmentId("CarApply.delete");
        String status = "failure";
        carapplyService.batchDelete(carapply);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of CarApply
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        CarApply carapply = new CarApply();
        carapply.setStatmentId("CarApply.queryAsList");
        BeanUtils.populate(carapply, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(carapply, pageMap);
        List<BaseModel> carapplyList = carapplyService.queryAsList(carapply);
        Map<String, Object> renderMap = GridUIMapper.render(carapply, carapplyList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of CarApply
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody CarApply carapply) throws Exception {
        carapply.setStatmentId("CarApply.queryAsObject");
        return carapplyService.queryAsObject(carapply);
    }

    @RequestMapping("/page")
    public String forword() {
        return "car/carapplyList";
    }

    @RequestMapping("/carcheck")
    public String goToCheckPage() {
        return "car/carcheckList";
    }

    @Resource
    public void setCarApplyService(CarApplyService carapplyService) {
        this.carapplyService = carapplyService;
    }
}
